-- CALC_RESEARCHER_WRECKAGE_BONUS

-- 计算研究员残骸奖励
return function(user, bonusArg)
    -- 元件列表
    local elementList = {
            [1004] = {7516, 7517, 7518},
            [1003] = {7519, 7520, 7521},
                        };

    -- 获取所在迷宫id
    local dungeonId = DungeonM.getDungeonId();
    dungeonId = DungeonAreaM.getParentId(dungeonId);
    local element = elementList[dungeonId];
    local ret = {};
    if type(element) ~= "table" or #element < 3 then
        return ret;
    end

    -- 如果没有工程学手册，必定获得(不在洞窟才产出)
    -- 67%概率：随机普通元件×2~3
    -- 33%概率：古代元件×1
    if ItemM.getAmount(user, 7509) == 0 and not DungeonInstanceM.isInInstance(ME.user) then

        -- 工程学手册获取通过开关控制，默认开启
        if EngineeringManualM.isOpen() == 1 then
            table.insert(ret, {1,7509,1});
        end

        for i = 1, #element do
            table.insert(ret, {1, element[i], 3});
        end

        return ret;
    end

    local arr = {
        {["class_id"] = element[1], ["count"] = 2, ["ratio"] = 100, },   -- 爆破元件×2
        {["class_id"] = element[1], ["count"] = 3, ["ratio"] = 100, },   -- 爆破元件×3
        {["class_id"] = element[2], ["count"] = 2, ["ratio"] = 100, },   -- 生化元件×2
        {["class_id"] = element[2], ["count"] = 3, ["ratio"] = 100, },   -- 生化元件×3
        {["class_id"] = element[3], ["count"] = 2, ["ratio"] = 100, },   -- 冶金元件×2
        {["class_id"] = element[3], ["count"] = 3, ["ratio"] = 100, },   -- 冶金元件×3
        {["class_id"] = 7522, ["count"] = 1, ["ratio"] = 300, },         -- 古代元件×1
    };

    local seed  = DungeonM.getRandSeed("CALC_RESEARCHER_WRECKAGE_BONUS");
    local info = fetchElemBySeed(arr, seed);

    local classId = info["class_id"];
    local count   = info["count"];

    local ret = {
        { 1, classId, count, },
    };

    -- 未来猫任务已经领取了，15%概率出未来猫道具
    local rand  = DungeonM.getRandSeed("CALC_RESEARCHER_WRECKAGE_BONUS");
    local prop = PropM.combine(user, "doraemon", "mission");
    if (prop[3] > 0 and not DungeonServiceM.isStatItemLimit(7577) and
        rand % 100 < 15) then
        table.insert(ret, { 1, 7577, 1 });
    end

    return ret;
end
